#ifndef _PATTERN_H_
#define _PATTERN_H_

#include <vector>
#include "Defines.h"
#include "CoffBucket.h"
#include "CoffChanger.h"

using namespace std;

class CPos
{
public:
	CPos( int frame, int x, int y ) { m_ucFrame = frame; m_usX = x; m_usY = y; };
public:
	unsigned char m_ucFrame;
	unsigned short m_usX;
	unsigned short m_usY;
};

class CPattern
{
public:
	CPattern( char * pattern_array, char * coff_array, unsigned int pattern_mask );
	~CPattern();
	bool DoMatch( char * pattern_array, CPos pos );

	bool DoInterplate();
	bool ChangeCoff();
	bool RecordPSNR( double psnr );

private:
	bool DoUpDownMirror();
	bool DoLeftRightMirror();
	bool DoUpDownLeftRightMirror();
	bool DoSort();
	void SwapBit( unsigned int &pattern, int bit1_index, int bit2_index );

public:
	unsigned int NormalizePatternForm( unsigned int pattern );
	bool SelectBestCoff();


	void Dump( bool dump_all = false );
	void DumpBucket();
	void DumpBestCoff();

public:
	unsigned int m_uiaPattern[MIRROR_TYPE_COUNT];
	char m_caCoff[MIRROR_TYPE_COUNT][REF_PIXEL_NUMBER];
	vector<CPos> * m_vecpaPosList[MIRROR_TYPE_COUNT];
	CCoffBucket * m_pCoffBucket;
	CCoffChanger * m_pCoffChanger;

private:
	unsigned int m_uiPatternMask;
};


#endif // _PATTERN_H_